package com.example.boot6rabbitmqalipay.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import  com.example.boot6rabbitmqalipay.bean.Message;

@Slf4j
@Component
public class RabbitmqSender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMessage(String exchange,String roukekey,Message content) {
        try {
            log.info("============发送消息给余额宝=========" + content);
            amqpTemplate.convertAndSend(
                    exchange,
                    roukekey,
                    JSONObject.toJSONString(content));
        }catch (Exception e) {

        }
    }
}
